package cn.stylefeng.guns.modular.vlt.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.comm.bean.BetweenMonth;
import cn.stylefeng.guns.comm.util.BetweenTimeUtil;
import cn.stylefeng.guns.modular.vlt.entity.Active;
import cn.stylefeng.guns.modular.vlt.model.params.ActiveParam;
import cn.stylefeng.guns.modular.vlt.service.ActiveService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 志愿活动信息表控制器
 *
 * @author
 * @Date 2020-12-16 11:07:24
 */
@Controller
@RequestMapping("/active")
public class ActiveController extends BaseController {

    private String PREFIX = "/vlt/active";

    @Autowired
    private ActiveService activeService;

    /**
     * 跳转到主页面
     *
     * @author
     * @Date 2020-12-16
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/active.html";
    }

    /**
     * 新增页面
     *
     * @author
     * @Date 2020-12-16
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/active_add.html";
    }

    /**
     * 编辑页面
     *
     * @author
     * @Date 2020-12-16
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/active_edit.html";
    }

    /**
     * 新增接口
     *
     * @author
     * @Date 2020-12-16
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ActiveParam activeParam) {
        this.activeService.add(activeParam);
        return ResponseData.success();
    }

    @RequestMapping("/cntA")
    @ResponseBody
    public ResponseData cntA() {
        return ResponseData.success(this.activeService.cntA());
    }

    /**
     * 编辑接口
     *
     * @author
     * @Date 2020-12-16
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ActiveParam activeParam) {
        this.activeService.update(activeParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author
     * @Date 2020-12-16
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ActiveParam activeParam) {
        this.activeService.delete(activeParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author
     * @Date 2020-12-16
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ActiveParam activeParam) {
        Active detail = this.activeService.getById(activeParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author
     * @Date 2020-12-16
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ActiveParam activeParam, String betweenMonthStr) {
        if (betweenMonthStr != null && betweenMonthStr.length() > 0) {
            BetweenMonth betweenMonthBean = BetweenTimeUtil.getBetweenMonth(betweenMonthStr, "至");
            activeParam.setBetweenMonth(betweenMonthBean);
        }
        return this.activeService.findPageBySpec(activeParam);
    }

}


